package jbl.action;
import java.util.List;

import jbl.pageModel.Menu;
import jbl.service.MenuServiceI;
import jbl.util.Json;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;
/**
 * 
 * @author jblcxg
 * 
 * 左侧导航菜单栏管理
 *
 */
@Namespace("/")
@Action(value="menuAction")
public class MenuAction extends BaseAction implements ModelDriven<Menu>{
	private Menu menu=new Menu();
	
	private MenuServiceI menuService;
	
	public MenuServiceI getMenuService() {
		return menuService;
	}
	@Autowired
	public void setMenuService(MenuServiceI menuService) {
		this.menuService = menuService;
	}
	@Override
	public Menu getModel() {
		return menu;
	}
	/**
	 * 获取树节点
	 */
	public  void getTreeNode(){
	  List<Menu> l =menuService.getTreeNode(menu.getId());
	  super.writeJson(l);
	}
	
	/**
	 * 获得treeGrid
	 */
	public void treeGrid(){
		try {
			List<Menu> list = menuService.treeGrid(menu.getId());
			writeJson(list);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			//logger.error("查询菜单列表失败:"+e.getMessage());
		}
	}
	/**
	 * 增加模块
	 */
	public void addNode(){
		Json j=new Json();
		try {
			menuService.addNode(menu);
			j.setSuccess(true);
			j.setMsg("添加成功");
		} catch (Exception e) {
			e.printStackTrace();
			j.setSuccess(false);
			j.setMsg("添加失败");
		}
		writeJson(j);
	}
	/**
	 * 修改模块
	 */
	public void update(){
		Json j=new Json();
		try {
			menuService.update(menu);
			j.setSuccess(true);
			j.setMsg("修改成功");
		} catch (Exception e) {
			e.printStackTrace();
			j.setSuccess(false);
			j.setMsg("修改失败");
		}
		writeJson(j);
	}
	
	/**
	 * 删除模块
	 */
	public void delete(){
			Json json = menuService.delete(menu.getId());
			writeJson(json);
	}
	/**
	 * 获取所有导航栏信息
	 */
	public void getAllMenu(){
		List<Menu> list = menuService.getAllMenu();
		writeJson(list);
	}
	/**
	 * 获取所有导航栏信息  下拉列表值
	 */
	public void comboboxInfo(){
		writeJson(menuService.comboboxInfo());
	}
}
